Skip to content

Update type for blob to be byte array, instead of sql.RawBytes#1274

Closed
APshenkin wants to merge 1 commit intomattn:masterfrom
APshenkin:patch-1
Closed

Update type for blob to be byte array, instead of sql.RawBytes#1274
APshenkin wants to merge 1 commit intomattn:masterfrom
APshenkin:patch-1

Conversation

@APshenkin
Copy link
Copy Markdown

After this PR was merged https://github.com/mattn/go-sqlite3/pull/909/files go-sqlite started return correct types for sqlite types.

However the change of type for BLOB ends up to the fact, that in GORM deserialization of byte arrays become string. The reason of this is because GORM cast all sql.RawBytes to strings for some reasons here https://github.com/go-gorm/gorm/blob/0daaf1747cfa4e4850376ad50a7834fb78b0cc0e/scan.go#L44
My assumption is that GORM do so, as a lot of drivers for different DBs return some good values for this sql.RawBytes. (here is example of issues raised go-gorm/gorm#5783)

I asked question in GORM repo about this go-gorm/gorm#7189, but some solution that can be is to change sql.RawBytes to reflect.SliceOf(reflect.TypeOf(byte(0))) (as it was before) to return BLOB as byte arrays there. This then should not introduce breaking changes nor in GORM nor in go-sqlite

@mattn
Copy link
Copy Markdown
Owner

mattn commented Mar 16, 2026

This is a workaround for a GORM issue. The fix should be done on the GORM side, not here.

@mattn mattn closed this Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants